<?php
namespace app\admin\controller;

use think\Session;
use app\common\controller\AdminBase;
use app\common\model\Defaultreply as DefaultreplyModel;

class Defaultreply extends AdminBase
{
    protected $defaultreply_model;
    protected $author_config;

    protected function _initialize(){
        parent::_initialize();
        $this->author_config = session::get('wechat_info');
        $this->defaultreply_model = new DefaultreplyModel;
    }

    public function index(){
        $content = $this->defaultreply_model->where('auid',$this->author_config['id'])->value('content');
        $this->assign('content',$content);
        return $this->fetch();
    }

    public function save(){
        $data = $this->request->post();
        if($this->defaultreply_model->where('auid',$this->author_config['id'])->find()){
            $result = $this->defaultreply_model->save($data,['auid'=>$this->author_config['id']]);
        } else {
            $data['auid'] = $this->author_config['id'];
            $result = $this->defaultreply_model->allowField(true)->save($data);
        }

        if($result){
            $this->success('保存成功');
        }else{
            $this->error('保存失败');
        }
    }
}